package com.ls.kdlss.ui.home;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.gm.common.utils.ToastUtil;
import com.gm.lib.views.titlebar.AbTitleBar;
import com.ls.kdlss.R;
import com.ls.kdlss.ui.home.tantan.CardFragment;
import com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 首页
 */
public class HomePagerFragment extends Fragment implements View.OnClickListener {


    @Bind(R.id.title_bar)
    AbTitleBar titleBar;
    @Bind(R.id.bt_shangchuan)
    Button btShangchuan;
    @Bind(R.id.container)
    LinearLayout llM;
    @Bind(R.id.imageView4)
    ImageView imageView4;

    public static HomePagerFragment getInstance() {

        return new HomePagerFragment();

    }


    private View view;


    @Override
    public void onStart() {
        super.onStart();
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.activity_homepage, null);
        ButterKnife.bind(this, view);
        titleBar.setTitleText("抢题");
        initImageLoader();
        if (savedInstanceState == null) {
             getFragmentManager().beginTransaction()
                    .add(R.id.container2, new CardFragment())
                    .commitAllowingStateLoss();
        }
        return view;
    }

    @OnClick({R.id.bt_shangchuan,R.id.imageView4})
    @Override
    public void onClick(View v) {

        switch (v.getId()) {

            case R.id.bt_shangchuan:
                ToastUtil.show("还没写");
                break;
            case R.id.imageView4:
                    FudaoSetupActivity.launch(getContext());
                break;

        }

    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }


    @SuppressWarnings("deprecation")
    private void initImageLoader() {
        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getContext())
                .memoryCacheExtraOptions(480, 800)
                // default = device screen dimensions
                .threadPoolSize(3)
                // default
                .threadPriority(Thread.NORM_PRIORITY - 1)
                // default
                .tasksProcessingOrder(QueueProcessingType.FIFO)
                // default
                .denyCacheImageMultipleSizesInMemory()
                .memoryCache(new LruMemoryCache(2 * 1024 * 1024))
                .memoryCacheSize(2 * 1024 * 1024).memoryCacheSizePercentage(13) // default
                .discCacheSize(50 * 1024 * 1024) // 缓冲大小
                .discCacheFileCount(100) // 缓冲文件数目
                .discCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default
                .imageDownloader(new BaseImageDownloader(getContext())) // default
                .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default
                .writeDebugLogs().build();

        // 2.单例ImageLoader类的初始化
        ImageLoader imageLoader = ImageLoader.getInstance();
        imageLoader.init(config);
    }
}
